//对于json相关类、函数，必须引用prototype.js
window.map=new Map();
function clear(){
		this.value="";
	}
function DataControler() {
	this.webRoot = "http://localhost:8080/PaaSofLogistics/";
	this.altUserInfo = function(userInfoId, value) {
		var url = this.webRoot + "json/altUserInfo";
		var params = "userInfoId=" + userInfoId + "value=" + value ;
		new Ajax.Request(url, {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true")
					window.map.put("altUserInfoTmp",true);
			},
			asynchronous : false
		});
		var tmp=window.map.get("altUserInfoTmp");
		window.map.removeByKey("altUserInfoTmp");
		return tmp;
	};
	this.displayUserInfoByUserInfoId = function(userInfoId) {
		var url = this.webRoot + "json/displayUserInfoByUserInfoId";
		var params = "userInfoId=" + userInfoId ;
		new Ajax.Request(url, {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true") {
					var tmpArray = removeArrayCell(res["result"], "flag");
					var headArray = Array("userInfoId", "userInfoKey","userInfoValue");
					window.map.put("displayUserInfoByUserInfoIdTmp",arrayTransform(tmpArray, headArray));
				}
			},
			asynchronous : false
		});
		var tmp=window.map.get("displayUserInfoByUserInfoIdTmp");
		window.map.removeByKey("displayUserInfoByUserInfoIdTmp");
		return tmp;
	};
	this.displayUserInfoByKey = function(key) {
		var url = this.webRoot + "json/displayUserInfoByKey";
		var params = "key=" + key ;
		new Ajax.Request(url, {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true") {
					var tmpArray = removeArrayCell(res["result"], "flag");
					var headArray = Array("userInfoId", "userInfoKey",
							"userInfoValue");
					window.map.put("displayUserInfoByKeyTmp",arrayTransform(tmpArray, headArray));
				}
			},
			asynchronous : false
		});
		var tmp=window.map.get("displayUserInfoByKeyTmp");
		window.map.removeByKey("displayUserInfoByKeyTmp");
		return tmp;
	};
	this.displayUserInfoByUserId = function() {
		var url = this.webRoot + "json/displayUserInfoByUserId";
		var params = "";

		new Ajax.Request(url, {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true") {
					var tmpArray = removeArrayCell(res["result"], "flag");
					var headArray = Array("userInfoId", "userInfoKey",
							"userInfoValue");
					window.map.put("displayUserInfoByUserIdTmp",arrayTransform(tmpArray, headArray));
				}
			},
			asynchronous : false
		});
		var tmp= window.map.get("displayUserInfoByUserIdTmp");
		window.map.removeByKey("displayUserInfoByUserIdTmp");
		return tmp;
	};
	this.addDistributeDaily = function(dailyDate, goodId, shopId, receipt,
			dailyFlag) {
		var url = this.webRoot + "json/addDistributeDaily";
		var params = "dailyId=" + dailyId + "&goodId=" + goodId+ "&shopId=" + shopId + "&receipt=" + receipt + "&dailyFlag=" + dailyFlag ;
		new Ajax.Request(url, {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true")
					window.map.put("addDistributeDaily",true);
			},
			asynchronous : false
		});
		var tmp= window.map.get("addDistributeDaily");
		window.map.removeByKey("addDistributeDaily");
		return tmp;
	};
	this.addUserInfo = function(key, value) {
		var url = this.webRoot + "json/addUserInfo";
		var params = "key=" + key + "&value=" + value ;
		new Ajax.Request(url, {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true")
					window.map.put("addUserInfoTmp",true);
			},
			asynchronous : false
		});
		var tmp=window.map.get("addUserInfoTmp");
		window.map.removeByKey("addUserInfoTmp");
		return tmp;
	};
	this.displayOneDistributeDaily = function(dailyId) {
		var url = this.webRoot + "json/displayOneDistributeDaily";
		var params = "dailyId=" + dailyId ;
		new Ajax.Request(url, {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true") {
					var tmpArray = removeArrayCell(res["result"], "flag");
					var headArray = Array("dailyId", "dailyDate", "goodId",
							"shopId", "receipt", "dailyFlag");
					window.map.put("displayOneDistributeDailyTmp",arrayTransform(tmpArray, headArray));
				}
			},
			asynchronous : false
		});
		var tmp=window.map.get("displayOneDistributeDailyTmp");
		window.map.removeByKey("displayOneDistributeDailyTmp");
		return tmp;
	};
	this.displayDistributeDaily = function(firstOfPage, maxOfPage, flag, shopId) {
		var url = this.webRoot + "json/displayDistributeDaily";
		var params = "first=" + firstOfPage + "&max=" + maxOfPage + "&flag=" + flag + "&shopId=" + shopId ;
		new Ajax.Request(url, {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true") {
					var tmpArray = removeArrayCell(res["result"], "flag");
					var headArray = Array("dailyId", "dailyDate", "goodId",
							"shopId", "receipt", "dailyFlag");
					window.map.put("displayDistributeDailyTmp",arrayTransform(tmpArray, headArray));
				}
			},
			asynchronous : false
		});
		var tmp=window.map.get("displayDistributeDailyTmp");
		window.map.removeByKey("displayDistributeDailyTmp");
		return tmp;
	};
	this.displayDistributeGoods = function(firstOfPage, maxOfPage) {
		var url = this.webRoot + "json/displayDistributeGoods";
		var params = "first=" + firstOfPage + "&max=" + maxOfPage ;
		new Ajax.Request(url, {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true") {
					var tmpArray = removeArrayCell(res["result"], "flag");
					var headArray = Array("goodId", "goodDescription",
							"goodPrice");
					window.map.put("displayDistributeGoodsTmp",arrayTransform(tmpArray, headArray));
				}
			},
			asynchronous : false
		});
		var tmp=window.map.get("displayDistributeGoodsTmp");
		window.map.removeByKey("displayDistributeGoodsTmp");
		return tmp;
	};
	this.displayOneDistributeGoods = function(goodId) {
		var url = this.webRoot + "json/displayOneDistributeGoods";
		var params = "goodId" + goodId ;

		new Ajax.Request(url, {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true")
					window.map.put("displayOneDistributeGoodsTmp", true);
			},
			asynchronous : false
		});
		var tmp=window.map.get("displayOneDistributeGoodsTmp");
		window.map.removeByKey("displayOneDistributeGoodsTmp");
		return tmp;
	};
	this.altDistributeGoods = function(goodId, goodDescription, price) {
		var url = this.webRoot + "json/altDistributeGoods";
		var params = "goodId" + goodId + "&goodDescription=" + goodDescription+ "&price" + price ;
		new Ajax.Request(url, {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true")
					window.map.put("altDistributeGoodsTmp", true);
			},
			asynchronous : false
		});
		var tmp=window.map.get("altDistributeGoodsTmp");
		window.map.removeByKey("altDistributeGoodsTmp");
		return tmp;
	};
	this.addDistributeShops = function(shopDescription) {
		var url = this.webRoot + "json/addDistributeShops";
		var params = "shopDescription=" + shopDescription ;
		new Ajax.Request(url, {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true")
					window.map.put("addDistributeShopsTmp", true);
			},
			asynchronous : false
		});
		var tmp=window.map.get("addDistributeShopsTmp");
		window.map.removeByKey("addDistributeShopsTmp");
		return tmp;
	};
	this.altDistributeShops = function(shopId, shopDescription) {
		var url = this.webRoot + "json/altDistributeShop";
		var params = "shopId=" + shopId + "&shopDescription="+ shopDescription ;
		new Ajax.Request(url, {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true")
					window.map.put("altDistributeShopsTmp", true);
			},
			asynchronous : false
		});
		var tmp=window.map.get("altDistributeShopsTmp");
		window.map.removeByKey("altDistributeShopsTmp");
		return tmp;
	};
	this.displayDistributeShops = function(firstOfPage, maxOfPage){
		var url = this.webRoot + "json/displayDistributeShops";
		var params = "first=" + firstOfPage + "&max=" + maxOfPage ;
		alert(2);
		new Ajax.Request(url, {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				alert(request.responseText);
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true") {
					var tmpArray = removeArrayCell(res["result"], "flag");
					var headArray = Array("shopId", "shopDescription");
					window.map.put("displayDistributeShopsTmp", arrayTransform(tmpArray, headArray));
				}else
					window.map.put("displayDistributeShopsTmp",null);
			},
			asynchronous : false
		});
		var tmp=window.map.get("displayDistributeShopsTmp");
		window.map.removeByKey("displayDistributeShopsTmp");
		return tmp;
	};
	this.displayDistributeUser = function(firstOfPage, maxOfPage) {
		var url = this.webRoot + "json/displayDistributeUser";
		var params = "first=" + firstOfPage + "&max=" + maxOfPage ;
		new Ajax.Request(url, {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true") {
					var tmpArray = removeArrayCell(res["result"], "flag");
					var headArray = Array("userId", "shopId", "userRight");
					window.map.put("displayDistributeUserTmp", arrayTransform(tmpArray, headArray));
				}
			},
			asynchronous : false
		});
		var tmp=window.map.get("displayDistributeUserTmp");
		window.map.removeByKey("displayDistributeUserTmp");
		return tmp;
	};
	this.displayOneDistributeShops = function(shopId) {
		var url = this.webRoot + "json/displayOneDistributeShops";
		var params = "shopId=" + shopId ;
		new Ajax.Request(url, {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true") {
					var tmpArray = removeArrayCell(res["result"], "flag");
					var headArray = Array("shopId");
					window.map.put("displayOneDistributeShopsTmp", arrayTransform(tmpArray, headArray));
				}
			},
			asynchronous : false
		});
		var tmp=window.map.get("displayOneDistributeShopsTmp");
		window.map.removeByKey("displayOneDistributeShopsTmp");
		return tmp;
	};
	this.displayOneDistributeUser = function(userId) {
		var url = this.webRoot + "json/displayOneDistributeUser";
		var params = "userId=" + userId ;

		new Ajax.Request(url, {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true") {
					var tmpArray = removeArrayCell(res["result"], "flag");
					var headArray = Array("userId");
					window.map.put("displayOneDistributeUserTmp", arrayTransform(tmpArray, headArray));
				}
			},
			asynchronous : false
		});
		var tmp=window.map.get("displayOneDistributeUserTmp");
		window.map.removeByKey("displayOneDistributeUserTmp");
		return tmp;
	};
	this.displayOneDistributeStock = function(stockId) {
		var url = this.webRoot + "json/displayOneDistributeStock";
		var params = "stockId=" + stockId ;
		new Ajax.Request(url, {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true") {
					var tmpArray = removeArrayCell(res["result"], "flag");
					var headArray = Array("stockId", "shopId", "goodId","cost", "count");
					window.map.put("displayOneDistributeStockTmp", arrayTransform(tmpArray, headArray));
				}
			},
			asynchronous : false
		});
		var tmp=window.map.get("displayOneDistributeStockTmp");
		window.map.removeByKey("displayOneDistributeStockTmp");
		return tmp;
	};
	this.displayDistributeStock = function(stockId, firstOfPage, maxOfPage) {
		var url = this.webRoot + "json/displayDistributeStock";
		var params = "stockId=" + stockId + "&first=" + firstOfPage 
				+ "max=" + maxOfPage ;
		new Ajax.Request(url, {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true") {
					var tmpArray = removeArrayCell(res["result"], "flag");
					var headArray = Array("stockId", "shopId", "goodId",
							"cost", "count");
					window.map.put("displayDistributeStockTmp", arrayTransform(tmpArray, headArray));
				}
			},
			asynchronous : false
		});
		var tmp=window.map.get("displayDistributeStockTmp");
		window.map.removeByKey("displayDistributeStockTmp");
		return tmp;
	};
	this.authorizeDistributeUser = function(userId, shopId, right) {
		var url = this.webRoot + "json/authorizeDistributeUser";
		var params = "userId=" + userId + "&shopId=" + shopId + "&right=" + right ;

		new Ajax.Request(url, {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true")
					window.map.put("authorizeDistributeUserTmp", true);
			},
			asynchronous : false
		});
		var tmp=window.map.get("authorizeDistributeUserTmp");
		window.map.removeByKey("authorizeDistributeUserTmp");
		return tmp;
	};
	this.registerDistributeUser = function(dbId, shopId) {
		var url = this.webRoot + "json/registerDistributeUser";
		var params = "dbId=" + dbId + "&shopId=" + shopId ;
		new Ajax.Request(url, {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true")
					window.map.put("registerDistributeUserTmp", true);
			},
			asynchronous : false
		});
		var tmp=window.map.get("registerDistributeUserTmp");
		window.map.removeByKey("registerDistributeUserTmp");
		return tmp;
	};
}
function User() {
	// 必须引用sha1算法,hex_sha1(字符串/变量)
	this.userId="";
	this.telephone = "";
	this.dataControler = "";
	this.userName = "";
	this.userPwd = "";
	this.userInfoMap = new Map();
	this.webRoot = "http://localhost:8080/platform/";
	this.deleteDB = function() {
		var url = this.webRoot + "json/deleteDB";
		// 插入提示，确定要删除数据库？
		new Ajax.Request(url, {
			method : "post",
			parameters : "",
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true")
					window.map.put("deleteDBTmp", true);
			},
			asynchronous : false
		});
		return window.map.get("deleteDBTmp");;
	};
	this.createDB = function() {
		var url = this.webRoot + "json/createDB";
		new Ajax.Request(url, {
			method : "post",
			parameters : "",
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true")
					window.map.put("createDBTmp", true);
			},
			asynchronous : false
		});
		return window.map.get("createDBTmp");;
	};
	this.changePwd = function(changePwdObject) {
		var url = this.webRoot + "json/changePwd";
		if (changePwdObject.userPwd[0] != changePwdObject.userPwd[1])
			return false;
		var params = "userName=" + changePwdObject.userName 
				+ "&userPwd[0]=" + changePwdObject.userPwd[0] 
				+ "&userPwd[1]=" + changePwdObject.userPwd[1] ;
		new Ajax.Request(url, {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true") {
					window.user.userName = changePwdObject.userName;
					window.user.userPwd = changePwdObject.userPwd[0];
					window.map.put("changePwdTmp",true);
				}
			},
			asynchronous : false
		});
		var tmp=window.map.get("changePwdTmp");
		return tmp;
	};
	this.logout = function() {
		var url = this.webRoot + "json/logout";
		var params = "";
		new Ajax.Request(url, {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				window.user.userName = "";
				window.user.userPwd = "";
				window.user.telephone = "";
				window.user.userInfoMap = new Map();
				window.user.dataControler = "";
				document.cookie = "";
			},
			asynchronous : true
		});
		return true;
	};

	this.getOneUserInfoByKey = function(key) {
		if (this.userInfoMap.get(key) != false
				&& this.userInfoMap.get(key) != null)
			return this.userInfoMap.get(key);
		var url = this.webRoot + "json/displayUserInfoByKey";
		var params = "key=" + key ;
		new Ajax.Request(url, {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				if (res["result"]["flag"] == "true")
					window.user.userInfoMap.put(key, res["result"]["userInfoValue"]);
			},
			asynchronous : false
		});
		return window.user.userInfoMap.get(key);
	};
	//changed
	this.login = function() {
		var url = this.webRoot + "json/login";
		var params = "userName=" + this.userName + "&userPwd="+this.userPwd;
		new Ajax.Request(
				url,
				{
					method : "post",
					parameters : params,
					onComplete : function(request) {
						var res = request.responseText.evalJSON();
						if (res["result"]["flag"] == "true") {
							window.user.userId=res["result"]["userId"];
							window.user.telephone = res["result"]["telephone"];
							window.user.dataControler = new DataControler();
							window.map.put("loginTmp",true);
						}
					},
					asynchronous : false
				});
		var tmp=window.map.get("loginTmp");
		window.map.removeByKey("loginTmp");
		return tmp;
	};
}
function removeArrayCell(targetArray, cellName) {
	var resultArray = Array();
	for ( var tmp in targetArray) {
		if (tmp != cellName)
			resultArray.push(targetArray[tmp]);
	}
	return resultArray;
}
function arrayTransform(targetArray, headArray) {
	var resultArray = Array();
	var i = 0;
	if (targetArray[headArray[0] + ":0"].inArray())
		for (; targetArray[headArray[0] + ":" + i].inArray(); i++) {
			var rowArray = Array();
			for ( var tmp in headArray)
				rowArray.push(targetArray[headArray[tmp] + ":" + i]);
			resultArray.push(rowArray);
		}
	else {
		var rowArray = Array();
		for ( var tmp in headArray)
			rowArray.push(targetArray[headArray[tmp]]);
		resultArray.push(rowArray);
	}
	return resultArray;
}
function CookieControler() {
	this.cookieArray = document.cookie.split(";");
	this.getCookie = function(key) {
		for ( var tmp in this.cookieArray)
			if (key == this.cookieArray[tmp].split("=")[0])
				return this.cookieArray[tmp].split("=")[1];
	};
	this.setCookie = function(key, value) {
		document.cookie += key + "=" + value ;
	};
	this.delCookie = function(key) {
		for ( var tmp in this.cookieArray)
			if (key == this.cookieArray[tmp].split("=")[0])
				return this.cookieArray[tmp] = "";
	};
}
function online(id) {
	new Ajax.Request(
			"http://localhost:8080/PaaSofLogisitics/online",
			{
				method : "post",
				parameters : "",
				onComplete : function(request) {
					var res = request.responseText.evalJSON();
					if (res["result"]["flag"] == "true")
						document.getElementById(id).innerHtml = res["result"]["online"];
				},
				asynchronous : true
			});
}
function writeTable(contentArray) {
	var result = "<table>";
	for ( var row in contentArray) {
		result += "<tr>";
		for ( var cell in contentArray[row]) {
			result += "<th>" + contentArray[row][cell] + "</th>";
		}
		result += "</tr>";
	}
	result += "</table>";
	return result;
}
function writeTableWithHead(headArray, contentArray) {
	var targetArray = Array();
	targetArray[0] = headArray;
	var iterator = 1;
	for ( var row in contentArray) {
		targetArray[iterator] = contentArray[row];
		iterator++;
	}
	return writeTable(id, targetArray);
}
function writeContentToHtml(id, content) {
	document.getElementByid(id).innerHtml = content;
}
function mapOfLispStyle(mapFunction, mapArray) {
	var resultArray = Array();
	for ( var tmp in mapArray) {
		resultArray[tmp] = mapFunction(mapArray[tmp]);
	}
	return resultArray;
}
function reduceOfClojureStyle(reduceFunction, reduceArray) {
	var flag = true;
	for ( var tmp in reduceArray) {
		if (flag) {
			flag = false;
			result = reduceArray[tmp];
		} else
			result = reduceFunction(reduceArray[tmp], result);
	}
	return result;
}
function isArray(obj) {
	return Object.prototype.toString.call(obj) === "[object Array]";
}
/*
 * MAP对象，实现MAP功能
 * 
 * 接口： size() 获取MAP元素个数 isEmpty() 判断MAP是否为空 clear() 删除MAP所有元素 put(key, value)
 * 向MAP中增加元素（key, value) remove(key) 删除指定KEY的元素，成功返回True，失败返回False get(key)
 * 获取指定KEY的元素值VALUE，失败返回NULL element(index)
 * 获取指定索引的元素（使用element.key，element.value获取KEY和VALUE），失败返回NULL containsKey(key)
 * 判断MAP中是否含有指定KEY的元素 containsValue(value) 判断MAP中是否含有指定VALUE的元素 values()
 * 获取MAP中所有VALUE的数组（ARRAY） keys() 获取MAP中所有KEY的数组（ARRAY）
 * 
 * 例子： var map = new Map();
 * 
 * map.put("key", "value"); var val = map.get("key") ……
 * 
 */
function Map() {
	this.elements = new Array();

	// 获取MAP元素个数
	this.size = function() {
		return this.elements.length;
	};

	// 判断MAP是否为空
	this.isEmpty = function() {
		return (this.elements.length < 1);
	};

	// 删除MAP所有元素
	this.clear = function() {
		this.elements = new Array();
	};

	// 向MAP中增加元素（key, value)
	this.put = function(_key, _value) {
		this.elements.push({
			key : _key,
			value : _value
		});
	};

	// 删除指定KEY的元素，成功返回True，失败返回False
	this.removeByKey = function(_key) {
		var bln = false;
		try {
			for (i = 0; i < this.elements.length; i++) {
				if (this.elements[i].key == _key) {
					this.elements.splice(i, 1);
					return true;
				}
			}
		} catch (e) {
			bln = false;
		}
		return bln;
	};

	// 删除指定VALUE的元素，成功返回True，失败返回False
	this.removeByValue = function(_value) {// removeByValueAndKey
		var bln = false;
		try {
			for (i = 0; i < this.elements.length; i++) {
				if (this.elements[i].value == _value) {
					this.elements.splice(i, 1);
					return true;
				}
			}
		} catch (e) {
			bln = false;
		}
		return bln;
	};

	// 删除指定VALUE的元素，成功返回True，失败返回False
	this.removeByValueAndKey = function(_key, _value) {
		var bln = false;
		try {
			for (i = 0; i < this.elements.length; i++) {
				if (this.elements[i].value == _value
						&& this.elements[i].key == _key) {
					this.elements.splice(i, 1);
					return true;
				}
			}
		} catch (e) {
			bln = false;
		}
		return bln;
	};

	// 获取指定KEY的元素值VALUE，失败返回NULL
	this.get = function(_key) {
		try {
			for (i = 0; i < this.elements.length; i++) {
				if (this.elements[i].key == _key) {
					return this.elements[i].value;
				}
			}
		} catch (e) {
			return false;
		}
		return false;
	};

	// 获取指定索引的元素（使用element.key，element.value获取KEY和VALUE），失败返回NULL
	this.element = function(_index) {
		if (_index < 0 || _index >= this.elements.length) {
			return null;
		}
		return this.elements[_index];
	};

	// 判断MAP中是否含有指定KEY的元素
	this.containsKey = function(_key) {
		var bln = false;
		try {
			for (i = 0; i < this.elements.length; i++) {
				if (this.elements[i].key == _key) {
					bln = true;
				}
			}
		} catch (e) {
			bln = false;
		}
		return bln;
	};

	// 判断MAP中是否含有指定VALUE的元素
	this.containsValue = function(_value) {
		var bln = false;
		try {
			for (i = 0; i < this.elements.length; i++) {
				if (this.elements[i].value == _value) {
					bln = true;
				}
			}
		} catch (e) {
			bln = false;
		}
		return bln;
	};

	// 判断MAP中是否含有指定VALUE的元素
	this.containsObj = function(_key, _value) {
		var bln = false;
		try {
			for (i = 0; i < this.elements.length; i++) {
				if (this.elements[i].value == _value
						&& this.elements[i].key == _key) {
					bln = true;
				}
			}
		} catch (e) {
			bln = false;
		}
		return bln;
	};

	// 获取MAP中所有VALUE的数组（ARRAY）
	this.values = function() {
		var arr = new Array();
		for (i = 0; i < this.elements.length; i++) {
			arr.push(this.elements[i].value);
		}
		return arr;
	};

	// 获取MAP中所有VALUE的数组（ARRAY）
	this.valuesByKey = function(_key) {
		var arr = new Array();
		for (i = 0; i < this.elements.length; i++) {
			if (this.elements[i].key == _key) {
				arr.push(this.elements[i].value);
			}
		}
		return arr;
	};

	// 获取MAP中所有KEY的数组（ARRAY）
	this.keys = function() {
		var arr = new Array();
		for (i = 0; i < this.elements.length; i++) {
			arr.push(this.elements[i].key);
		}
		return arr;
	};

	// 获取key通过value
	this.keysByValue = function(_value) {
		var arr = new Array();
		for (i = 0; i < this.elements.length; i++) {
			if (_value == this.elements[i].value) {
				arr.push(this.elements[i].key);
			}
		}
		return arr;
	};

	// 获取MAP中所有KEY的数组（ARRAY）
	this.keysRemoveDuplicate = function() {
		var arr = new Array();
		for (i = 0; i < this.elements.length; i++) {
			var flag = true;
			for ( var j = 0; j < arr.length; j++) {
				if (arr[j] == this.elements[i].key) {
					flag = false;
					break;
				}
			}
			if (flag) {
				arr.push(this.elements[i].key);
			}
		}
		return arr;
	};
}
Array.prototype.inArray = function(e) {
	for (i = 0; i < this.length && this[i] != e; i++)
		;
	return !(i == this.length);
}